package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Applications;
import com.example.springboot.entity.jobs;
import com.example.springboot.service.JobApplicationService;
import com.example.springboot.service.JobSearchService;
import com.example.springboot.service.impl.JobApplicationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 职位搜索Controller
 *
 * @author 柏旭东
 * @date 2024-6-20
 */
@CrossOrigin(origins = "http://localhost:7070")
@RestController
@RequestMapping("/JobApplication")
public class JobApplicationController {

    @Autowired
    private  JobSearchService jobSearchService;

    @Autowired
    private JobApplicationService jobApplicationService;

    @Autowired
    private JobApplicationServiceImpl jobApplicationServiceImpl;

    public JobApplicationController(JobSearchService jobSearchService) {
        this.jobSearchService = jobSearchService;
    }

    /**
     *
     * 展示所有职位信息
     */
    @GetMapping
    public Result findAllJobs() {
            List<jobs> jobsList = jobSearchService.findAllJobs();
            return Result.success(jobsList);
    }


    /**
     *
     * 提交申请信息
     */
    @PostMapping("/apply")
    public ResponseEntity<Applications> applyForJobs(@RequestParam("student_id") Long studentId,
                                                     @RequestParam("job_id") List<Long> jobIds) {
        applyForJobs(studentId, jobIds);
        return ResponseEntity.ok().build();

    }

    /**
     *
     * 所有职位申请信息
     */
    @GetMapping("/applyMessage")
    public Result findAllApplications(){
        List<Applications> applications = jobApplicationService.findAllApplications();
        return Result.success(applications);
    }
}
